package com.jc.camerascan.wxapi;

import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.jc.camerascan.R;
import com.jc.camerascan.core.BaseActivity;
import com.jc.camerascan.entity.event.WXPaySuccessEvent;
import com.jc.camerascan.utils.XToastUtils;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.xuexiang.xutil.common.logger.Logger;

import org.greenrobot.eventbus.EventBus;

/**
 * @ProjectName: PhotoRecognition
 * @Package: com.jc.camerascan.wxapi
 * @ClassName: WXPayEntryActivity
 * @Description: java类作用描述
 * @Author: XuChi
 * @CreateDate: 2020/7/17 16:20
 * @Version: 1.0
 */
public class WXPayEntryActivity extends AppCompatActivity implements IWXAPIEventHandler {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_empty);
        IWXAPI api = WXAPIFactory.createWXAPI(this, WxConstants.WX_APP_ID);
        api.handleIntent(getIntent(), this);
    }

//    @Override
//    protected int getLayoutId() {
//        return R.layout.activity_empty;
//    }

    @Override
    public void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager.LayoutParams windowParams = window.getAttributes();
        windowParams.alpha = 1f;//1.０全透明．０不透明．
        window.setAttributes(windowParams);
    }


    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp baseResp) {
        Logger.e("errCode: " + baseResp.errCode);
        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                EventBus.getDefault().post(new WXPaySuccessEvent());
                break;
            case BaseResp.ErrCode.ERR_COMM:
                XToastUtils.error("支付失败");
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                XToastUtils.error("您取消了支付");
                break;
        }
        finish();
    }

}
